/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * Project Name: lmrp-android app
 * Create Time: 16-2-16 下午6:42
 */

package com.lenovo.mso2o.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lenovo.framework.base.BaseListAdapter;
import com.lenovo.framework.util.ViewHolder;
import com.lenovo.mso2o.R;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by lenovo on 2015/11/16.
 */
public class MenuSelectAdapter extends BaseListAdapter<String> {
    //private int index = 0;
    private Context mContext;

    /**
     * list == null, not save adater data state, list!=null, save it's state
     * util next shown
     *
     * @param list
     */
    public MenuSelectAdapter(List<String> list, Context context) {
        super(list);
        mContext = context;
    }


    @Override
    protected View getNextView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(parent.getContext(), R.layout.item_orderlistcondition_selectdistance, null);
        }
        TextView textView =  ViewHolder.get(convertView, R.id.text_orderlistActiveFragmentTitle_conditionDistancelistItem);
        ImageView image_checked =  ViewHolder.get(convertView, R.id.image_conditionSelected_orderlist);
        String jsonString = getItem(position).toString();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(jsonString);
            String text = jsonObject.getString("text");
            textView.setText(text);
            if (index == position) {//设置字体颜色
                textView.setTextColor(parent.getResources().getColor(R.color.blue_accent));
                image_checked.setVisibility(View.VISIBLE);
            } else {
                textView.setTextColor(parent.getResources().getColor(R.color.black_accent));
                image_checked.setVisibility(View.INVISIBLE);
            }
            //take_photo_to_sign
            //android:textColor="#999999"
            //android:textSize="13sp"
            if(mContext.getString(R.string.so_long_to_sign).equals(text)){
                image_checked.setVisibility(View.INVISIBLE);
                textView.setGravity(Gravity.CENTER);
                textView.setTextSize(13);
                textView.setTextColor(Color.parseColor("#999999"));
            }

            if(mContext.getString(R.string.take_photo_to_sign).equals(text)){
                textView.setTextColor(parent.getResources().getColor(R.color.blue_accent));
                image_checked.setVisibility(View.INVISIBLE);
                textView.setGravity(Gravity.CENTER);
                textView.setTextSize(15);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return convertView;
    }

    @Override
    protected void onReachBottom() {

    }
}
